{extend name="base" /}
{block name="content"}
<style>
    html, body { background: #F5F5F5;}
</style>
<div class="g-login">
    <form class="m-login">
        <h2>{$site_info.site_name}</h2>
        <ul>
            <li>
                <label for="username">用户名</label>
                <input type="text" name="username" id="username" class="u-ipt" placeholder="请输入用户名" />
            </li>
            <li>
                <label for="password">密码</label>
                <input type="password" name="password" id="password" class="u-ipt u-pwd" placeholder="请输入密码" />
            </li>
            <li>
                <input type="text" name="code" class="u-ipt u-ipt-code" placeholder="请输入验证码" />
                <img src="{:captcha_src()}" alt="captcha" class="u-captcha" onclick="this.src='{:captcha_src()}'" />
            </li>
            <li><button id="j_login" class="u-btn">登录</button></li>
        </ul>
        <p>&copy; 2017-2018</p>
    </form>
</div>
{/block}
{block name="extrajs"}
<script>
    $(function(){
        layui.use('layer', function(){
            $('#j_login').on('click', function(){
            	addDisabled('#j_login');
                    $user       = $('input[name="username"]'),

                    $pass       = $('input[name="password"]'),

                    $code       = $('input[name="code"]');

                

                if ($user.val() == '' || $pass.val() == '' || $code.val() == '') {

                    dialog.error('请输入用户名、密码、验证码');

                    removeDisabled('#j_login');

                    return false;
                }
                
                var index = layer.load(1, {
                    shade: [.6, '#000']
                });
                
                username = aesEncrypt($user.val());

                password = aesEncrypt($pass.val());

                code     = aesEncrypt($code.val());
                
                $.ajax({
                    url: '{:url("login")}',
                    type: 'POST',
                    data: {username: username, password: password, code: code},
                    dataType: 'json',
                    success: function(ret){
                        layer.close(index);
                        if (ret.status == 0) {

                            top.location.href = '{:url("manage/Index/index")}';

                        } else {
                            dialog.error(ret.message);
                            $('.u-captcha').attr('src', '{:captcha_src()}');
                        }

                        removeDisabled('#j_login');

                    },
                    error: function(){
                        layer.close(index);
                        dialog.error('服务器错误，请稍后重试！');

                        removeDisabled('#j_login');

                    }
                });
                return false;
            });
            
            $('input').keyup(function(event){
                if (event.keyCode == 13) {
                    $('input').blur();
                }
            })
        });
    })
</script>
{/block}